package studio.raptor.ddal.core.engine.plan.node.impl.ddl;

import studio.raptor.ddal.core.engine.ProcessContext;
import studio.raptor.ddal.core.engine.plan.node.ForkingNode;
import studio.raptor.ddal.core.parser.result.ParseResult;
import studio.raptor.ddal.core.parser.result.SQLStatementType;

/**
 * 判断SQL中有无 "drop index" 操作
 * @author liujy
 * @since 1.0
 */
public class HasDDLIndexDrop extends ForkingNode {

  @Override
  protected int judge(ProcessContext context) {
    return judge0(context.getStatementContext().getParseResult(),context.getStatementContext().getOriginSql()) ? 0 : 1;
  }

  private boolean judge0(ParseResult parseResult,String originSql){
    SQLStatementType sqlStatementType=parseResult.getSqlType();
    if("DDL".equals( sqlStatementType.getType())){
      originSql=originSql.toLowerCase();
      if(originSql.contains( "drop") && originSql.contains( "index" ) ){
        return true;
      }
    }
    return false;
  }

}
